package image2

import "errors"

type Rectangle struct {
	X      int
	Y      int
	Color  string
	Width  int
	Height int
}

func (r *Rectangle) Process(canvas *Canvas) error {
	var endX, endY = r.X + r.Width, r.Y + r.Height
	if endX > canvas.Width || endY > canvas.Height {
		return errors.New("数组越界！")
	}
	color := rgbaColor(r.Color, 255)
	for x := r.X; x < endX; x++ {
		for y := r.Y; y < endY; y++ {
			if canvas.Placeholder[x][y] == 1 {
				continue
			}
			canvas.Placeholder[x][y] = 1
			canvas.Canvas.Set(x, y, color)
		}
	}
	return nil
}
